Function Reference

GUICtrlRead

Read state or data of a control.

GUICtrlRead ( controlID [, advanced] )

 

Parameters

controlID The control identifier (controlID) as returned by a GUICtrlCreate... function.
advanced [optional] returns extended information of a control.
0 = (Default) Returns a value with state or data of a control.
1 = Returns extended information of a control (see Remarks).

 

Return Value

Success: Returns depending the control (see below).
Failure: Returns 0.
Type Value
Checkbox, Radio state of the button. See State table
Combo, List The value selected
Input, Edit The text entered
Button The display text
Date The selected date
Progress Current percentage
Slider Current value
Tab The number or the controlID of the tabitem selected depending of the advanced parameter value.
Menu, MenuItem State of the menu/item. See State table
TreeView Control identifier (controlID) of the selected TreeViewItem
TreeViewItem State of the TreeViewItem
ListView Control identifier (controlID) of the selected ListViewItem. 0 means no item is selected
Dummy The value set by GUICtrlSendToDummy or GUICtrlSetData

 

Remarks

In 'advanced' mode the return value contains additional data of the control (see below).

Note: not for all known controls there is additional data available!


Type Additional Value
Checkbox, Radio The text of the control.
Menu, MenuItem The text of the control.
TreeView The text of the current selected TreeViewItem.
TreeViewItem The text of the TreeViewItem.
ListViewItem The state of the ListViewItem if $LVS_EX_CHECKBOXES exStyle used in advanced mode. See State table
Tab The controlID of the tabitem selected

For Checkbox, Radio control several states can be returned as $GUI_FOCUS and $GUI_CHECKED,. So use i.e. BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the control is checked.

For Listview items several states can be returned as $GUI_CHECKED and $GUI_UNCHECKED (only for listview controls with LVS_EX_CHECKBOXES-exstyle and on 'advanced' return) . So use i.e. BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the item is checked.

For Treeview items several states can be returned as $GUI_FOCUS, $GUI_EXPAND and $GUI_CHECKED, $GUI_UNCHECKED (only for treeview controls with TVS_CHECKBOXES-style . So use i.e. BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the item is checked.

 

Related

GUICtrlSet..., GUIGetMsg, GUIEventOptions (Option)

 

Example


#include <GUIConstants.au3>

GUICreate("My GUICtrlRead") ; will create a dialog box that when displayed is centered

$menu1  = GUICtrlCreateMenu("File")

$n1     = GUICtrlCreateList("", 10, 10, -1, 100)
GUICtrlSetData(-1, "item1|item2|item3", "item2")

$n2     = GUICtrlCreateButton("Read", 10, 100, 50)
GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button

GUISetState () ; will display an empty dialog box
; Run the GUI until the dialog is closed
Do
    $msg = GUIGetMsg()
    if $msg = $n2 Then
        Msgbox(0, "Selected listbox entry", GUICtrlRead($n1)) ; display the selected listbox entry
        $menustate  = GUICtrlRead($menu1) ; return the state of the menu item
        $menutext   = GUICtrlRead($menu1, 1) ; return the text of the menu item
        Msgbox(0, "State and text of the menuitem", "state:" & $menustate & @LF & "text:" & $menutext)
    EndIf
Until $msg = $GUI_EVENT_CLOSE